//
//  BaseNavigationViewController.swift
//  SunxianhuaTestApp
//
//  Created by abc on 2021/10/11.
//

import Foundation
import UIKit

class BaseNavigationViewController:  UINavigationController{

    override func viewDidLoad() {
        super.viewDidLoad()
        self.navigationBar.barTintColor = UIColor.white
    }
    
    
    //MARK: - 设置导航栏按钮便利方法
    @discardableResult
    open func setLeftItem(style: ItemStyle, target: Any?, action: Selector?) -> UIBarButtonItem {
        let item : UIBarButtonItem = .item(with: style, target: target, action: action)
        
        self.navigationItem.leftBarButtonItem = item
        return item
    }
    
    @discardableResult
    open func setRightItem(style: ItemStyle, target: Any?, action: Selector?) -> UIBarButtonItem {
        let item : UIBarButtonItem = .item(with: style, target: target, action: action)
        self.navigationItem.rightBarButtonItem = item
        return item
    }
    
    @discardableResult
    open func addLeftItem(style: ItemStyle, target: Any?, action: Selector?) -> UIBarButtonItem {
        let item : UIBarButtonItem = .item(with: style, target: target, action: action)
        guard let _ = self.navigationItem.leftBarButtonItems else {
            self.navigationItem.leftBarButtonItem = item
            return item
        }

        self.navigationItem.leftBarButtonItems?.append(item)
        return item
    }
    
    @discardableResult
    open func addRightItem(style: ItemStyle, target: Any?, action: Selector?) -> UIBarButtonItem {
        let item : UIBarButtonItem = .item(with: style, target: target, action: action)
        guard let _ = self.navigationItem.rightBarButtonItems else {
            self.navigationItem.rightBarButtonItem = item
            return item
        }
        self.navigationItem.rightBarButtonItems?.append(item)
        return item
    }
    
}
